<!--用户管理页-->
<template>
  <div style="height: 6vh;background-color:#fff;padding:10px 20px;">
    <span style="line-height:60px;font-size:20px;float: left">简历信息</span>
  </div>
  <!-- 新增用户弹窗 -->
  <el-dialog :title="dialogTitle" style="width:600px;padding:40px;" v-model="dialogVisible" :before-close="handleClose">
    <el-form label-width="50px" label-position="top">
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="简历名称">
            <el-input placeholder="请输入简历名称" v-model="saveResumeForm.resumeName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="自我介绍">
            <el-input placeholder="请输入自我介绍" v-model="saveResumeForm.intro"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="学校">
            <el-input placeholder="请输入学校" v-model="saveResumeForm.school1"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="学校地址">
            <el-input placeholder="请输入本科学校" v-model="saveResumeForm.school2"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
<!--      <el-row :gutter="30">-->
<!--        <el-col :span="12">-->
<!--          <el-form-item label="研究生学校">-->
<!--            <el-input placeholder="请输入研究生学校" v-model="saveResumeForm.school3"></el-input>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col :span="12">-->
<!--          <el-form-item label="求职状态">-->
<!--            <el-select placeholder="请选择求职状态" v-model="saveResumeForm.jobStatus">-->
<!--              <el-option v-for="item in levelOptions" :label="item.label" :value="item.value"></el-option>-->
<!--            </el-select>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
<!--      </el-row>-->
    </el-form>
    <template #footer>
      <el-button  @click="handleClose()" style="color: #5B63B7;" class="custom-hover-color">取消</el-button>
      <el-button type="primary" color="#5B63B7" @click="saveResume()">保存</el-button>
    </template>
  </el-dialog>
  <!-- 简历查询卡片 -->
  <el-card style="margin:20px;height: 80px;">
    <el-form :inline="true">
      <el-form-item label="学校" style="float: left">
        <el-input placeholder="输入学校" style="width:220px;"
                  v-model="searchResumeForm.school1" @keydown.enter="loadResume"></el-input>
      </el-form-item>
      <el-form-item label="学校地址" style="float: left">
        <el-input placeholder="输入学校地址" style="width:220px;"
                  v-model="searchResumeForm.school2" @keydown.enter="loadResume"></el-input>
      </el-form-item>
<!--      <el-form-item label="研究生学校" style="float: left">-->
<!--        <el-input placeholder="输入研究生学校" style="width:220px;"-->
<!--                  v-model="searchResumeForm.school3" @keydown.enter="loadResume"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="简历名称" style="float: left">
        <el-input placeholder="输入简历名称" style="width:220px;"
                  v-model="searchResumeForm.resumeName" @keydown.enter="loadResume"></el-input>
      </el-form-item>
<!--      <el-form-item label="求职状态" style="width:300px;float: left">-->
<!--        <el-select placeholder="请选择求职状态"-->
<!--                   v-model="searchResumeForm.jobStatus" @change="loadResume">-->
<!--          <el-option v-for="item in levelOptions" :label="item.label" :value="item.value"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item style="float: left">
        <el-button @click="resetSearch">重置</el-button>
        <el-button type="primary" @click="loadResume" color="#5B63B7">查询</el-button>
      </el-form-item>
    </el-form>
  </el-card>
  <!-- 用户信息表格 -->
  <el-card style="margin:20px;">
    <el-table :data="ResumeArr">
      <el-table-column type="index" label="编号" width="80" align="center"/>
      <el-table-column prop="resumeName" label="简历名称" align="center"/>
      <el-table-column prop="username" label="用户名" align="center"/>
<!--      <el-table-column prop="jobStatus" label="求职状态" align="center"/>-->
      <el-table-column prop="intro" label="自我介绍" align="center"/>
<!--      <el-table-column prop="resumeFile" label="简历文件" align="center"/>-->
      <el-table-column prop="school1" label="学校" align="center"/>
      <el-table-column prop="school2" label="学校地址" align="center"/>
<!--      <el-table-column prop="school3" label="研究生学校" align="center"/>-->
<!--      <el-table-column prop="recommend" label="智能推荐" align="center">-->
<!--        <template #default="scope">-->
<!--          <el-switch @change="changeStatus(scope.row.id,scope.row.recommend)" active-value="1" inactive-value="0" v-model="scope.row.recommend"></el-switch>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column prop="createTime" label="创建时间" align="center"/>
      <el-table-column prop="updateTime" label="更新时间" align="center"/>
      <el-table-column label="操作" align="center">
        <template #default="scope">
<!--          <el-button link type="primary" size="small" @click="editResume(scope.row.id)" style="color:#5B63B7">编辑</el-button>-->
          <el-button link type="primary" size="small" @click="deleteResume(scope.row.id)" style="color:#5B63B7">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
import qs from "qs";

//控制新增用户弹窗是否显示
const dialogVisible = ref(false);
//定义变量控制dialog的标题
const dialogTitle = ref('编辑简历信息');
//准备对象用来收集新增/修改投递简历的表单信息
const saveResumeForm = ref({
  id:'',
  username:'',
  resumeName: '',
  userId:'',
  intro:'',
  resumeFile: '',
  school1:'',
  school2:'',
  school3:'',
  recommend:'',
  createTime:'',
  updateTime:''
});
//求职状态
// const levelOptions = ref([
//   {label: '在校生',value: '在校生'},
//   {label: '应届生',value: '应届生'},
// ])
//定义数组用来装用户列表信息
const ResumeArr = ref([]);
//定义对象保存查询条件
const searchResumeForm = ref({resumeName: '',school1:'',school2:''});
const loadResume = () => {
  //如果传入了查询条件，则根据条件查询，没有条件，默认查询所有员工信息
  let data = qs.stringify(searchResumeForm.value);
  console.log(data);
  axios.get(BASE_URL+'/v1/resume/select?'+data).then((response) => {
    if (response.data.code === 2000) {
      ResumeArr.value = response.data.data;
      console.log(ResumeArr.value);
    } else {
      ElMessage.error(response.data.msg);
    }
  })
}

const saveResume = () => {
  let data = JSON.stringify(saveResumeForm.value);
  console.log(data);
  axios.post(BASE_URL+'/v1/resume/save',data, {
    headers: {
      'Content-Type': 'application/json' // 明确指定请求体类型为 JSON
    }
  }).then((response) => {
    if (response.data.code === 2000) {
      ElMessage.success('保存成功!');
      dialogVisible.value = false;//关闭弹窗
      saveResumeForm.value={};//清空输入的数据,防止新增成功后打开弹窗还是之前的数据
      loadResume();//加载用户列表方法
    } else {
      ElMessage.error(response.data.msg);
    }
  })
}

//实现取消按钮的功能
const handleClose = ()=>{
  if(confirm('是否关闭本窗口?')){
    //用户确认关闭后,将审批弹窗与确认驳回弹窗一起关掉
    dialogVisible.value = false;
    //取消时把填的数据都清空，表单回复到初始状态
    saveResumeForm.value={};
  }
}

//页面一加载立即调用
onMounted(() => {
  searchResumeForm.value={};
  loadResume();//加载员工列表
})

//重置用户搜索信息
const resetSearch = ()=>{
  searchResumeForm.value={};
  loadResume();
}


//编辑员工
const editResume = (id) =>{
  console.log(id);
  //修改弹窗标题并打开弹窗
  dialogTitle.value = '编辑简历信息';
  dialogVisible.value = true;
  //根据id查询要修改的当前员工的信息
  axios.get(BASE_URL+'/v1/resume/select?id='+id).then((response) => {
    if (response.data.code === 2000) {
      //若请求成功，赋值给saveUserForm，因为后端返回的是list，所以这里要data[0]
      saveResumeForm.value = response.data.data[0];
      console.log(response.data.data)
    } else {
      ElMessage.error(response.data.msg);
    }
  })
}

//删除用户
const deleteResume = (id)=>{
  console.log(id);
  if(confirm('您确认要删除此简历吗?')){
    axios.post(BASE_URL+'/v1/resume/delete/'+id).then((response) => {
      if (response.data.code === 2000) {
        ElMessage.success('删除成功!');
        loadResume();
      } else {
        ElMessage.error(response.data.msg);
      }
    })
  }
}

//修改智能推荐
const changeStatus = (id,recommend) => {
  axios.post(BASE_URL+'/v1/resume/update/'+id+'/'+recommend).then((response) => {
    if (response.data.code === 2000) {
      //ElMessage.success('修改成功!');
    } else {
      ElMessage.error(response.data.msg);
    }
  })
}
</script>

<style scoped>
.custom-hover-color:hover {
  color: #5B63B7; /* 悬停时的文本颜色 */
  background-color: #f5f5f5;
  border-color: #cccccc;
}
/*出生日期*/
.demo-datetime-picker {
  display: flex;
  width: 100%;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: stretch;
}
.demo-datetime-picker .block {
  padding: 30px 0;
  text-align: center;
}
</style>